<aside class="right-side">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <?php
        $name="";
        $urlloai = $_GET["url"];
        if ($urlloai == "1" || $urlloai == "2") {
            if ($urlloai == "1") {
                  $name= "Liên kết";
                echo '<h1>Quản lí liên kết.</h1>';
            } else {
                $name= "Điều hướng";
                echo '<h1>Quản lí điều hướng.</h1>';
            }
        } else {
           echo '<script>window.location.assign("'.WEB_PATH.'/404.html");</script>';
            die;
        }
        ?>


        <ol class="breadcrumb">
            <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i> Quản lí</a></li>
            <li><a href="javascript:void(0);">Admin</a></li>
            <li class="active">Quản lí <?php echo $name; ?></li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <div class="row" id="catalogparent">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"> <i class="fa fa-bars"></i> Danh sách <?php echo $name; ?></h3>
                    </div><!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">

                        <table class="table table-hover">
                            <tr>
                                <th>STT</th>
                                <th>Tên <?php echo $name; ?></th>
                                <th>Đường dẫn </th>
                                <th>Ngày tạo</th>
                                <th>Cập nhật</th>
                                
                                <th>Trạng thái</th>
                                <th>#</th>
                            </tr>
                            <tbody id="listcata">

                            </tbody>

                            <tr id="addcatalog" style="display: none;">
                                <td>---</td>
                                <td><input type="text" name="urlname" id="urlname" placeholder="Nhập tên <?php echo $name; ?>"/></td>
                                <td>
                                    <input type="text" name="urllink" id="linkurl" placeholder="Nhập đường dẫn <?php echo $name; ?>"/>
                                </td>


                                <td> <?php echo Date("d/m/Y"); ?></td>
                                <td> <?php echo Date("d/m/Y"); ?></td>
                                <td><span class="label label-primary">---------</span></td>
                                <td>
                                    <span id="btnaddevent" style="cursor: pointer;" class="label label-primary"><i class="fa fa-plus"></i> Thêm mới</span>    
                                </td>
                            </tr>
                            <tr id="showerr" style="display:none;">
                                <td colspan="7" style="color: #ff0033;" id="errcata">

                                </td>

                            </tr>
                            <tr>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/link/load" id="urlshow"/>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/link/addlink" id="urladd"/>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/link/dellink" id="urldel"/>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/link/active" id="urlactive"/>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/link/changeparent" id="urlchnageparent"/>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/link/loadedit" id="urldataedit"/>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/link/edit" id="urledit"/>
                            <input type="hidden" value="<?php echo WEB_PATH; ?>/systemadmin/catalog/showindex" id="urlshowindex"/>
                            <td colspan="7" style="text-align: center;"><a id="btnAddcata" href="javascript:void(0);">Thêm mới <?php echo $name; ?></a></td>

                            </tr>
                        </table>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div>
        </div>
        <!--meu parent -->


    </section><!-- /.content -->
</aside><!-- /.right-side -->
<script>
    $(document).ready(function() {
        loadlink();
        $("#btnAddcata").click(function() {
            $("#addcatalog").toggle();
        });
        $("#refeshbtn").click(function() {
            $("#catalogselect").val("0");
            loadcata();
        });
        $("#btnaddevent").click(function() {
            var urlname = $("#urlname").val();
            if (urlname == "") {
                $("#errcata").html("Bạn chưa nhập tên.");
                $("#showerr").slideDown(200);
            } else {
                var urllink = $("#linkurl").val();
                if (urllink == "") {
                    $("#errcata").html("Bạn chưa nhập đường dẫn.");
                    $("#showerr").slideDown(200);
                } else {
                    var urlfull = window.location.href.split("=");
                    var linkloai = urlfull[1];
                    $.ajax({
                        url: $("#urladd").val(),
                        type: "POST",
                        cache: false,
                        data: "urlname=" + urlname + "&urllink=" + urllink + "&linkloai=" + linkloai,
                        success: function(dataserver) {
                            var data = dataserver.split(":::");
                            if (data[0] != "") {
                                $("#errcata").html(data[0]);
                                $("#showerr").slideDown(200);
                            } else {
                                $("#urlname").val("");
                                $("#linkurl").val("");
                                $("#addcatalog").slideDown(200);
                                loadlink();
                            }
                        }
                    });
                }
            }
        });
    });
    function loadlink() {
        var urlfull = window.location.href.split("=");
        var linkloai = urlfull[1];
        $.ajax({
            url: $("#urlshow").val(),
            type: "POST",
            cache: false,
            data: "action=load&linkloai=" + linkloai,
            success: function(dataserver) {
                var data = dataserver.split(":::");
                $("#listcata").html(data[0]);

            }
        });
    }
    function delcatalog(linkId) {

        var mes = '<p class="warning-del">Bạn có muốn xóa dữ liệu này không?<br/>Quá trình này sẽ xóa hết các dữ liệu liên quan.</p><br/>' +
                '<span class="checkdel "><a onclick="confrimdel(' + linkId + ');" href="javascript:void(0);" class="ok">Xác nhận</a></span>' +
                '<span class="checkdel"> <a onclick="closedel();" href="javascript:void(0);" class="ok">Hủy</a></span>';
        $("#ctmes").html(mes);
        $("#warning").show();
    }
    function closedel() {
        $("#warning").hide();
    }
    function confrimdel(linkId) {
        var url = $("#urldel").val();
        $("#ctmes").html('<p class="warning-del">Đang xử lí...</p><br/>');
        $.ajax({
            url: url,
            type: "POST",
            cache: false,
            data: "action=delcatalog&linkId=" + linkId,
            success: function(dataserver) {
                var data = dataserver.split("*duypc*");

                var mes = '<p class="warning-del">' + data[0] + '</p><br/>' +
                        '<span class = "checkdel"><a onclick = "closedel();" href = "javascript:void(0);" class = "ok" > OK </a></span >';
                $("#ctmes").html(mes);
                if (data[1] == "delok") {
                    $("#" + linkId).remove();
                }
            }
        });
    }

    function setActive(linkId, active) {
        var url = $("#urlactive").val();
        $.ajax({
            url: url,
            type: "POST",
            cache: false,
            data: "action=load&linkId=" + linkId + "&active=" + active,
            success: function(dataserver) {
                loadlink();

            }
        });
    }
    function modal(linkId) {
        $('#catalogselectchange option[value=' + parentId + ']').attr('selected', 'selected');
        $(".modal-footer").html('<button type="button" class="btn btn-default" data-dismiss="modal">Hủy</button>' +
                '<button onclick="changeparent(' + linkId + ');" type="button" class="btn btn-primary">Thay đổi</button>');
        $("#changesmodalparent").modal("show");
    }
    function changeparent(catalogId) {
        var url = $("#urlchnageparent").val();
        var parentId = $("#catalogselectchange").val();
        $.ajax({
            url: url,
            type: "POST",
            cache: false,
            data: "action=load&catalogId=" + catalogId + "&parentId=" + parentId,
            success: function(dataserver) {
                $("#changesmodalparent").modal("hide");
                location.reload();
            }
        });
    }
    function modalchange(linkId) {
        var url = $("#urldataedit").val();
        $.ajax({
            url: url,
            type: "POST",
            cache: false,
            data: "action=load&linkId=" + linkId,
            success: function(dataserver) {
                var data = dataserver.split("*duypc*");
                $("#catalognamechange").val(data[0]);
                $("#catalogdeschange").val(data[1]);
                $("#editcatalog").modal("show");
                $(".modal-footer").html('<button type="button" class="btn btn-default" data-dismiss="modal">Hủy</button>' +
                        '<button onclick="editcatalog(' + linkId + ');" type="button" class="btn btn-primary">Thay đổi</button>');

            }
        });

    }
    function editcatalog(linkId) {
        var linkname = $("#catalognamechange").val();
        if (linkname == "") {
            $("#catalognamechange").focus();
        } else {
            var linkurl = $("#catalogdeschange").val();
            $.ajax({
                url: $("#urledit").val(),
                type: "POST",
                cache: false,
                data: "linkname=" + linkname + "&linkurl=" + linkurl + "&linkId=" + linkId,
                success: function(dataserver) {
                    //var data = dataserver.split(":::");
                    $("#editcatalog").modal("hide");
                    loadlink();
                }
            });
        }
    }
    function showindex(catalogId, flag) {
        $.ajax({
            url: $("#urlshowindex").val(),
            type: "POST",
            cache: false,
            data: "catalogId=" + catalogId + "&flag=" + flag,
            success: function(dataserver) {
                loadcata();
            }
        });
    }

</script>


<!--------Edith------->

<div class="modal fade" id="editcatalog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Chỉnh sửa liên kết/ điều hướng</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>Tên liên kết / điều hướng:</label>
                    <div class="input-group">
                        <input id="catalognamechange" type="text" class="form-control timepicker"/>
                        <div class="input-group-addon">
                            <i class="fa fa-certificate"></i>
                        </div>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->
                <div class="form-group">
                    <label>Đường dẫn:</label>
                    <div class="input-group">
                        <input id="catalogdeschange" type="text" class="form-control timepicker"/>
                        <div class="input-group-addon">
                            <i class="fa fa-certificate"></i>
                        </div>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->
            </div>
            <div class="modal-footer">

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->